package exception;

/**
 * 异常处理细节
 */
public class TryCatchDetail02 {

    public static void main(String[] args) {
        /*
            如果 try 代码块有可能有多个异常
            可以使用多个 catch 分别捕获不同的异常，相应处理
            要求子类异常写在前面，父类异常写在后面
         */
        try {
            Person person = new Person();
            //person = null;
            System.out.println(person.getName());
            int n1 = 10;
            int n2 = 20;
            int res = n1 / n2;//ArithmeticException
        }
        catch (NullPointerException e) {
            System.out.println("空指针异常=" + e.getMessage());
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {

        }

    }
}

class Person {

    private String name = "jack";

    public String getName() {
        return name;
    }
}